import SwiftUI

// LookGridItem
// 看一看商品展示

struct LookGridItem: View {
    var book: Book
    
    var body: some View {
        VStack(alignment: .center) {
            let firstImageURL = book.imageId.first != nil ? URL(string: "http://62.234.45.120:1230/storage/bookImage/" + book.imageId.first! + ".jpeg") : URL(string: "http://62.234.45.120:1230/static/avatar/default.png")
            
            AsyncImage(url: firstImageURL) { image in
                image
                    .resizable()
                    .scaledToFit()
                    .frame(width: 150, height: 150, alignment: .center)
            } placeholder: {
                ProgressView()
            }
            
            HStack {
                Text(book.tag)
                    .font(.caption)
                    .multilineTextAlignment(.leading)
                .padding(.vertical, 3)
                
                Spacer()
                
                Text(String(format: "¥%.2f", Double(book.requirePrice) / 100))
                    .font(.title3)
                    .foregroundColor(.orange)
                    .multilineTextAlignment(.trailing)
                    .padding(.vertical, 3)
            }
            
            Text(book.bookName)
                .font(.headline)
                .foregroundColor(.black)
                .multilineTextAlignment(.leading)
                
            
        }
        .padding()
        .background(Color.gray.opacity(0.1))
        .cornerRadius(10)
    }
}

#Preview {
    LookGridItem(book: DefaultBook)
}
